//
// Created by yangchao on 2022/5/7.
// 50. Pow(x, n): https://leetcode-cn.com/problems/powx-n/
//

#include <cmath>
#include <iostream>
using namespace std;

//快速幂法
class Pow{
public:
    double myPow(double x, int n) {
        if (x == 0.0) return 0.0;
        double res = 1.0;
        x = n >= 0? x : 1/x;
        n = abs(n);
        while (n > 0) {
            if (n%2 == 1) res *= x;
            x *= x;
            n >>= 1;
        }
        return res;
    }
};

int main() {
    Pow pow1;
    double res = pow1.myPow(2.000,10);
    cout << res;
}

